<form method="post" id="frmCompany" action="<?= base_url() ?>company/popupadd">
    <div class="modal-body">
        <div class="span5">
            <div class="row">
                <div class="span2">Nama</div>
                <input type="text" name="txtName" class="span3" id="txtName" value="<?= @$low->company_ename ?>"/>
                <font class="strerr"><?= @$err->officename ?></font>
            </div>
            <div class="row">
                <div class="span2">Propinsi</div>
                <select name="ddPropinsi" id="ddPropinsi">
                    <option value="">Select</option>
                    <? foreach (getPropinsi() as $k => $v) { ?>
                        <option value="<?= $v->province_id ?>"><?= $v->province_nama ?></option>
                    <? } ?>
                </select>
                <font class="strerr"><?= @$err->homeprovinceid ?></font>
            </div>
            <div class="row">
                <div class="span2">Kota</div>
                <select name="ddKota" id="ddKota">
                    <option value="">Select</option>
                </select>
                <font class="strerr"><?= @$err->homecityid ?></font>
            </div>
            <div class="row">
                <div class="span2">Alamat</div>
                <textarea name="txtAddr" class="span3" id="txtAddr"><?= @$low->company_address ?></textarea>
                <font class="strerr"><?= @$err->company_address ?></font>
            </div>
            <div class="row">
                <div class="span2">Deskripsi</div>
                <textarea name="txtDescr" class="span3" id="txtDescr"><?= @$low->company_description ?></textarea>
                <font class="strerr"><?= @$err->descr ?></font>
            </div>
        </div>
    </div>
    <div style="clear: both;"></div>
    <div class="modal-footer">
        <input type="submit" class="btn btn-primary" value="Simpan"/>
        <a href="#" class="btn btn-inverse" onclick="batal()">Batal</a>
    </div>
</form>
<script>
    function batal(){
<? if ($this->uri->segment(3) != "admin"): ?>
            $('#free').load("<?= base_url() ?>company/popup");
<? else : ?>
            $('#free').modal('hide');
<? endif; ?>
    }
    $("#frmCompany").submit(function(event) {
        event.preventDefault();
        var $form = $( this ),
        url = $form.attr( 'action' );
        console.log($form.serialize());
        $.post(url, $form.serialize(),
        function(data){
            if(data.code == 1 ){
                setCompany(data.id, data.txtName);
            }else{
                alert(data.err);
            }
        }, "json");
    });
    $('#ddPropinsi').change(function(){
        $('#ddKota').empty();
        $.post('<?= base_url() . "region/kabupaten" ?>', {id:$('#ddPropinsi').val()}, function(data) {
            if(data){
                var datajs = $.parseJSON(data);
                $('<option value="">Select</option>').appendTo("#ddKota");
                $.each(datajs, function(key, value){
                    $("<option value='"+value.city_id+"'>"+value.city_nama+"</option>").appendTo("#ddKota");
                });
            }
        });
    });
    $(".modal").css({
        'width' : '500',
        'margin-top':($(window).height()-$(".modal").height())/2, 
        'top':'0',
        'margin-left':($(window).width()-500)/2, 
        'left' : '0'
    }) ;
</script>